#include "registerdialog.h"
#include "ui_registerdialog.h"
#include <QDebug>
RegisterDialog::RegisterDialog(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::RegisterDialog)
{
    ui->setupUi(this);
    ui->lineEdit_2->setEchoMode(QLineEdit::Password);
}

RegisterDialog::~RegisterDialog()
{
    delete ui;
}
/////////////////////////////////////////注册//////////////////////////////////////////
void RegisterDialog::on_pushButton_clicked()
{
    //query.exec("drop table users");//删除整表
    query.exec("create table users(username varchar(20) primary key,password varchar(20))");//创建表,注册时用户名不能相同
    QString username=ui->lineEdit->text();
    QString password=ui->lineEdit_2->text();
    QString cmd("insert into users values('");
    cmd+=username;
    cmd+="','";
    cmd+=password;
    cmd+="')";
    bool res=query.exec(cmd);
    if(res)
    {
        QString mytitle="消息框";
        QString myinfo="注册成功！";
        QMessageBox::information(this,mytitle,myinfo);
        this->hide();
        ui->lineEdit->clear();
        ui->lineEdit_2->clear();
    }
    else
    {
        QString mytitle="提示框";
        QString myinfo="注册失败！用户名已存在！";
        QMessageBox::warning(this,mytitle,myinfo);
        ui->lineEdit->clear();
        ui->lineEdit_2->clear();
    }

}
